//
//  JWCalendarsScheduleViewController.m
//  SiqiCalendar
//
//  Created by sunjiawen on 2018/4/17.
//  Copyright © 2018年 sjw. All rights reserved.
//

#import "JWCalendarsScheduleViewController.h"
#import "PaperButton.h"
#import "UIViewController+LGSideMenuController.h"
#import "JWCalendarNameCollectionViewCell.h"
#import "JWDateCollectionViewCell.h"
#import "JWContentCollectionViewCell.h"

static NSString * kCollectionViewCellIDCalendarName = @"JWCalendarNameCollectionViewCellID";
static NSString * kCollectionViewCellIDDate = @"JWDateCollectionViewCellID";
static NSString * kCollectionViewCellIDContent = @"JWContentCollectionViewCellID";

@interface JWCalendarsScheduleViewController ()<LGSideMenuDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (nonatomic, strong) PaperButton *cancelBtn;
@end

@implementation JWCalendarsScheduleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initialData];
    
    [self setupUI];
}

#pragma mark - Private
/**
 初始化数据
 */
- (void)initialData {
    
}

/**
 配置UI
 */
- (void)setupUI {
    self.title = @"Title";
    
    self.sideMenuController.delegate = self;
    
//    if (@available(iOS 11.0, *)) {
//        [self.navigationController.navigationBar setPrefersLargeTitles:YES];
//        self.navigationController.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeAutomatic;
//        [self.navigationController.navigationBar setLargeTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];
//    }
//    
    self.cancelBtn = ({
        PaperButton *cancelBtn = [PaperButton button];
        
        [cancelBtn addTarget:self action:@selector(untoggleController:) forControlEvents:UIControlEventTouchUpInside];
        cancelBtn;
    });
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:self.cancelBtn];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"configure"] style:UIBarButtonItemStylePlain target:self action:@selector(settingCalendarConfig:)];
    
    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([JWContentCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:kCollectionViewCellIDContent];
    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([JWCalendarNameCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:kCollectionViewCellIDCalendarName];
    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([JWDateCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:kCollectionViewCellIDDate];
    
}

#pragma mark - LGSideMenuDelegate
- (void)willShowRightView:(UIView *)rightView sideMenuController:(LGSideMenuController *)sideMenuController {
    if (_cancelBtn) {
        [_cancelBtn animateToClose];
    }
}

- (void)willHideRightView:(UIView *)rightView sideMenuController:(LGSideMenuController *)sideMenuController {
    if (_cancelBtn) {
        [_cancelBtn animateToMenu];
    }
}

- (void)didHideRightView:(UIView *)rightView sideMenuController:(LGSideMenuController *)sideMenuController {
    if (_cancelBtn) {
        [_cancelBtn animateToMenu];
    }
}

- (void)didShowRightView:(UIView *)rightView sideMenuController:(LGSideMenuController *)sideMenuController {
    if (_cancelBtn) {
        [_cancelBtn animateToClose];
    }
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 108;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 18;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        // 第一行
        // - 日历名
        JWCalendarNameCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCollectionViewCellIDCalendarName forIndexPath:indexPath];
        cell.backgroundColor = [UIColor whiteColor];
        cell.calendarNameLabel.text = [NSString stringWithFormat:@"%ld,%ld",indexPath.section,indexPath.row];
        return cell;
    }else {
        
        if (indexPath.row == 0) {
            // 第一列 - 日期
            JWDateCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCollectionViewCellIDDate forIndexPath:indexPath];
            cell.dateLabel.text = [NSString stringWithFormat:@"%ld,%ld",indexPath.section,indexPath.row];
            cell.backgroundColor = [UIColor whiteColor];
            return cell;
        }else {
            // 排班内容
            JWContentCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCollectionViewCellIDContent forIndexPath:indexPath];
            cell.contentLabel.text = [NSString stringWithFormat:@"%ld,%ld",indexPath.section,indexPath.row];
            cell.backgroundColor = [UIColor whiteColor];
            return cell;
        }
    }
}

#pragma mark - UICollectionViewDelegate

#pragma mark - Actions
- (void)untoggleController:(PaperButton *)paper {
    [self.sideMenuController hideRightViewAnimated:YES completionHandler:nil];
}

- (void)settingCalendarConfig:(id)sender {
    
}

#pragma mark - Getter
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
